﻿@{
    ViewBag.Title = "";
    var id = Model != null ? Model.ID : 0;
}
@using ZBJF.Warranty.BLL
@using ZBJF.Warranty.Common.Enums.Data
@using ZBJF.Warranty.WebProvider
@model ZBJF.Warranty.Model.InsuranceProducts
@section Header{
    @Scripts.Render("~/bundles/datatable")
    @Styles.Render("~/Content/datatable")
}
<ul id="myTab" class="nav nav-tabs">
    <li class="active"><a href="#li1" data-toggle="tab" onclick="Reset('insuranceProductPackageList')">保险产品列表</a></li>
    @if (Convert.ToInt32(Request["Type"]) != 1)
    {
        <li class="Add-R"><a href="#li2" data-toggle="tab" onclick="Reset('sellerInsuranceProductsList')">保险卡产品列表</a></li>
    }
</ul>
<div id="myTabContent" class="tab-content" style="overflow: hidden;">
    <div class="table-responsive dataTables_wrapper nav nav-tabs tab-pane padding-10 fade in active" id="li1">
        <table class="keep-all">
            <tr>
                <th>保险产品名称：</th>
                <td>
                    @Html.TextBoxFor(c => c.ProductName, new { maxlength = 20, @class = "input-small" })
                </td>
                <th>创建时间：</th>
                <td colspan="1">
                    @Html.TextBox("CreateTimeStart", "", new { maxlength = 20, @class = "Wdate input-small", onclick = "WdatePicker()" })-
                    @Html.TextBox("CreateTimeEnd", "", new { maxlength = 20, @class = "Wdate input-small", onclick = "WdatePicker()" })
                </td>
                <td>
                    <input id="btnSubmit" class="btn btn-primary Search-R" type="button" value="查询" onclick="search();">
                </td>
            </tr>
        </table>
        <table id="sellerInsuranceProductsList" class="table table-striped table-bordered table-hover">
            <thead>
                <tr>
                    <th width="10"><input type="checkbox" id="ckbAll" /></th>
                    <th width="20">序号</th>
                    <th width="140">保险产品名称</th>
                    <th width="60">保额</th>
                    <th width="60">保险期限</th>
                </tr>
            </thead>
        </table>
        <div class="form-actions control-group align-center">
            <input id="btnConfirm" class="btn btn-primary Edit-R" type="submit" value="提交">
            <input id="btnClear" class="btn btn-primary Edit-R" type="submit" value="取消" onclick="parent.layer.closeAll();">
        </div>
    </div>
    <div class="table-responsive dataTables_wrapper tab-pane padding-10 fade in" id="li2">
        @RenderPage("/Views/SellerInsuranceProducts/SearchPanel.cshtml")
        <table id="insuranceProductPackageList" class="table table-striped table-bordered table-hover">
            <thead>
                <tr>
                    <th width="10"><input type="checkbox" id="ckbAll1" /></th>
                    <th width="20">序号</th>
                    <th width="120">保险卡卡号</th>
                    <th width="120">保险卡产品名称</th>
                    <th width="120">激活期限</th>
                    <th width="80">创建时间</th>
                </tr>
            </thead>
        </table>
        <div class="form-actions control-group align-center">
            <input id="ProductPackageadd" class="btn btn-primary Search-R" type="button" value="提交">
            <input class="btn btn-primary Search-R" type="button" value="取消" onclick="parent.layer.closeAll();">
        </div>
    </div>
</div>
@section scripts{
    <script type="text/javascript">
        var isSearch = false;
        $(function () {
            var objTable = $("#sellerInsuranceProductsList")
                .dataTable({
                    fnDrawCallback: function () {
                        ControlPermissionOperate();
                    },
                    "sAjaxSource": "/InsuranceProducts/Index?IsAvailable=True",
                    aoColumns: [
                        {
                            "mData": null,
                            "bSortable": false,
                            "fnRender": function (nRow) {
                                return "<input type='checkbox' name='checkList' class='CheckBoxItem' value='" + nRow.aData.ID + "'>";
                            }
                        },
                        {
                            "mData": null,
                            "bSortable": false,
                            "fnRender": function (nRow) {
                                return nRow.iDataRow + 1;
                            }
                        },
                        { "mData": "ProductName" },
                         { "mData": "Coverage" },
                         {
                             "mData": null, fnRender: function (nRow) {
                                 let _h = "";
                                 if (nRow.aData.PolicyPeriodYear && nRow.aData.PolicyPeriodYear > 0)
                                     _h += nRow.aData.PolicyPeriodYear + "年";
                                 if (nRow.aData.PolicyPeriodMonth && nRow.aData.PolicyPeriodMonth > 0)
                                     _h += nRow.aData.PolicyPeriodMonth + "月";
                                 if (nRow.aData.PolicyPeriodDay && nRow.aData.PolicyPeriodDay > 0)
                                     _h += nRow.aData.PolicyPeriodDay + "日";
                                 return _h;
                             }
                         }
                    ]
                });
            var objTable1 = $("#insuranceProductPackageList")
                .dataTable({
                    fnDrawCallback: function () {
                        ControlPermissionOperate();
                    },
                    "aaSorting": [[5, "desc"]],
                    "sAjaxSource": "/SellerInsuranceProducts/Index?IsAvailable=True",
                    aoColumns: [
                        {
                            "mData": null,
                            "bSortable": false,
                            "fnRender": function (nRow) {
                                return "<input type='checkbox' name='checkList' class='CheckBoxItem' value='" + nRow.aData.ID + "'>";
                            }
                        },
                        {
                            "mData": null,
                            "bSortable": false,
                            "fnRender": function (nRow) {
                                return nRow.iDataRow + 1;
                            }
                        },
                        { "mData": "InsuranceProductPackageNO" },
                        { "mData": "ProductPackageName" },
                        {
                            "mData": null, fnRender: function (nRow) {
                                return nRow.aData.ActiveCardInLimitDays + "天";
                            }
                        },
                        { "mData": "CreateTime" }
                    ]
                });
            initCheckBoxItem("sellerInsuranceProductsList", "@(Request["multiselect"] == "true")");
            initCheckBoxItem("insuranceProductPackageList", "True");

            function getSelectedItems(type) {
                var objTableName = type == 0 ? objTable : objTable1;
                var nTrs = objTableName.fnGetNodes(); //fnGetNodes获取表格所有行，nTrs[i]表示第i行tr对象
                var selectedItems = [];
                for (var i = 0; i < nTrs.length; i++) {
                    if ($(nTrs[i]).hasClass('selected')) {
                        selectedItems.push(objTableName.fnGetData(nTrs[i]));
                    }
                }
                return selectedItems;
            }

            $("#btnConfirm").click(function () {
                var items = getSelectedItems(0);
                if (!items || items == "" || items.length < 1) {
                    layer.alert("请选择保险产品！");
                    return;
                }
                parent.setSelectInsuranceProduct(items, false);
                parent.layer.closeAll();
            });
            $("#ProductPackageadd").click(function () {
                var items = getSelectedItems(1);
                if (!items || items == "" || items.length < 1) {
                    layer.alert("请选择保险产品！");
                    return;
                }
                parent.setSelectInsuranceProduct(items, true);
                parent.layer.closeAll();
            });
        });

        function search() {
            /*给查询对象赋值*/
            queryParamList.ProductName = $("#ProductName").val();
            queryParamList.InsuranceProductCategory = $("#InsuranceProductCategory").val();
            queryParamList.CreateTimeStart = $("#CreateTimeStart").val();
            queryParamList.CreateTimeEnd = $("#CreateTimeEnd").val();
            $("#sellerInsuranceProductsList").dataTable().fnDraw();
        }
        function Reset(reloadTableID) {
            $("#" + reloadTableID).dataTable().fnDraw();
        }
    </script>
}
